package testrj.traverser;

public class ObjectTraverser {
	private StrategyFactory factory = null;

	public void traverse(Object object) {
		try {
			for (NodeStrategy strategy : factory.customStrategiesAsList()) {
				if (strategy.canHandle(object)) {
					strategy.handle(object, this);
					return;
				}
			}
			for (NodeStrategy strategy : factory.defaultStrategies()) {
				if (strategy.canHandle(object)) {
					strategy.handle(object, this);
					return;
				}
			}
			factory.anyObjectNodeStrategy().handle(object, this);
		} catch (Throwable th) {
			factory.handleException(th);
		}
	}

	public static ObjectTraverser newInstance(StrategyFactory strategiesForTraversal) {
		ObjectTraverser traverser = new ObjectTraverser();
		traverser.factory = strategiesForTraversal;
		return traverser;
	}

	private ObjectTraverser() {
	}
}